package Java2Test.mythread.threadtest1;

public class MyRunnable implements Runnable {

    static int ticket = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (MyRunnable.class) {
                if (ticket == 1000) {
                    break;//票卖完了
                } else {
                    try {
                        Thread.sleep(3);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    ticket++;
                    System.out.println(Thread.currentThread().getName() + "正在卖第"
                            + ticket + "张票, 还剩" + (1000 - ticket) + "张票");

                }
            }

        }
    }
}
